<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
    <%@ page import="java.sql.ResultSet" %>
<%@ page import="java.sql.SQLException" %>
<%@ page import="java.util.logging.Level,java.util.logging.Logger" %>
<%@ page import="java.sql.Statement"%>
<%@page import="java.sql.Connection,java.sql.DriverManager" %>
<%@ page import="java.net.URLDecoder" %>

<%
	
	String cinema_name = request.getParameter("cinema_name");
	if (cinema_name != null && cinema_name.length() > 0)
		cinema_name = URLDecoder.decode(cinema_name, "UTF-8");
	
	String movie_name = request.getParameter("movie_name");
	if (movie_name != null && movie_name.length() > 0)
		movie_name = URLDecoder.decode(movie_name, "UTF-8");
	
	String movie_src = request.getParameter("movie_src");
	
	String date = request.getParameter("date");
	if (date != null && date.length() > 0)
		date = URLDecoder.decode(date, "UTF-8");
	
	String time = request.getParameter("time");
	
	String language = request.getParameter("language");
	if (language != null && language.length() > 0)
		language = URLDecoder.decode(language, "UTF-8");
	
	String seat = request.getParameter("seat");
	if (seat != null && seat.length() > 0)
		seat = URLDecoder.decode(seat, "UTF-8");
	
	String ticket_number = request.getParameter("ticket_number");
	String price = request.getParameter("price");
	/*String id = "01";
	String trainNum = "G2314";
	String startStation = "航海";
	String endStation = "滚动";*/
	//wanted_movie_src = "movie_1";
	
	Connection con=null;
	Statement stmt=null;
	ResultSet rs=null;
	int number = 0;
	String driver="com.mysql.cj.jdbc.Driver";
	String url="jdbc:mysql://localhost:3306/android?serverTimezone=GMT&characterEncoding=utf-8";
	String user="root";
	String passwd="HandQuite229";
    try{
       Class.forName(driver);
       con=DriverManager.getConnection(url, user, passwd);
       if (con == null)
      		System.out.println("con is null");
       }catch(ClassNotFoundException e){
           out.println(e);
       }catch(SQLException e){
    	   out.println(e);
       }
	try{
		stmt=con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,   
                ResultSet.CONCUR_UPDATABLE);
		String sql = "select * from order_info where id = (select max(id) from order_info)";
		
		System.out.println(sql);
		rs = stmt.executeQuery(sql);
		
		while(rs.next()){
			number = rs.getInt(1);
		}
		System.out.println(number);
		
	}catch (SQLException ex) {
		out.println(ex);
	}

	try{
		stmt=con.createStatement();
		number++;
		String sql2 = "insert into order_info values(" + number + ", '" + cinema_name + "', '"
				+ movie_name + "', '" + movie_src + "', '" + date + "', '" + time + "', '"
				+ language + "', '" + seat + "'," + ticket_number + ", " + price +")";
		
		System.out.println(sql2);
		int temp = stmt.executeUpdate(sql2);
		if (temp != 0)
			out.println("true");
		else
			out.println("false");
		
		con.close();
	}catch (SQLException ex) {
		out.println(ex);
	}
%>
